/* exchange sort */
/* input int num = number of elements */
/* input int* arr_ptr = array of elements for sorting */
/* output int* buff = sorted array */＿
/* output int error = error check code */

int exchange_sort (int* buff, int num, int* arr_ptr) {
  int i, j, last, switchTmp;

  for (i=0; i<num; i++) {
    buff[i] = arr_ptr[i];
    last = i;
    for (j=(last-1); j>=0; j--) {
      if (buff[j] < buff[last]) {
        break;
      }
      else {
        switchTmp = buff[j];
        buff[j] = buff[last];
        buff[last] = switchTmp;
        last--;
      }
    }
  }
  
  return 0; 
}

